﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NewAI
{
    public partial class TankInfoBox : UserControl
    {
        public TankInfoBox()
        {
            InitializeComponent();
        }

        private int tankID;
        private bool isSurvival;
        private Point position;
        private float threatDegree;
        private float profitDegree;
        private string fightMethod;

        public int TankID
        {
            set
            {
                groupBox1.Text = "坦克ID = " + value;
                tankID = value;
            }
            get => tankID;
        }
        public bool IsSurvival
        {
            set
            {
                label31.Text = IsSurvival ? "存活" : "死亡";
                isSurvival = value;
            }
            get => isSurvival;
        }
        public Point Position
        {
            set
            {
                label25.Text = $"({value.X},{value.Y})";
                position = value;
            }
            get => position;
        }
        public float ThreatDegree
        {
            set
            {
                label23.Text = value.ToString();
                threatDegree = value;

                if (value == -1)
                {
                    label8.Text = "风险---";
                    label6.Text = "---";
                    return;
                }

                ShowThreatDegreeValue(value);
                ShowProportion();
            }
            get => threatDegree;
        }

        public float ProfitDegree
        {
            set
            {
                label5.Text = value.ToString();
                profitDegree = value;
                if (value == -1)
                {
                    label1.Text = "风险---";
                    label3.Text = "---";
                    return;
                }
                ShowProfitDegreeValue(value);
                ShowProportion();
            }
            get => profitDegree;
        }

        public string FightMethod
        {
            get => fightMethod;
            set
            {
                fightMethod = value;
                label10.Text = value;
            }
        }

        private void ShowThreatDegreeValue(double value)
        {
            double temp;
            if (value <= 1e+2)
            {
                temp = value;
                label8.Text = "风险1百";
            }
            else if (value <= 1e+3)
            {
                temp = value / 10;
                label8.Text = "风险1千";
            }
            else if (value <= 1e+4)
            {
                temp = value / 1e+2;
                label8.Text = "风险1万";
            }
            else if (value <= 1e+5)
            {
                temp = value / 1e+3;
                label8.Text = "风险10万";
            }
            else if (value <= 1e+6)
            {
                temp = value / 1e+4;
                label8.Text = "风险100万";
            }
            else if (value <= 1e+7)
            {
                temp = value / 1e+5;
                label8.Text = "风险1000万";
            }
            else
            {
                label8.Text = "大于1000万";
                progressBar1.Value = progressBar1.Maximum;
                label6.Text = "100%";
                return;
            }
            progressBar1.Value = (int)temp;
            label6.Text = $"{Math.Round(temp, 1)}%";
        }

        private void ShowProfitDegreeValue(double value)
        {
            double temp;
            if (value <= 1e+2)
            {
                temp = value;
                label1.Text = "收益1百";
            }
            else if (value <= 1e+3)
            {
                temp = value / 10;
                label1.Text = "收益1千";
            }
            else if (value <= 1e+4)
            {
                temp = value / 1e+2;
                label1.Text = "收益1万";
            }
            else if (value <= 1e+5)
            {
                temp = value / 1e+3;
                label1.Text = "收益10万";
            }
            else if (value <= 1e+6)
            {
                temp = value / 1e+4;
                label1.Text = "收益100万";
            }
            else if (value <= 1e+7)
            {
                temp = value / 1e+5;
                label1.Text = "收益1000万";
            }
            else
            {
                label1.Text = "大于1000万";
                progressBar4.Value = progressBar4.Maximum;
                label3.Text = "100%";
                return;
            }
            progressBar4.Value = (int)temp;
            label3.Text = $"{Math.Round(temp, 1)}%";
        }

        private void ShowProportion()
        {
            if (threatDegree == -1 || profitDegree == -1)
            {
                progressBar2.Value = 0;
                progressBar2.BackColor = Color.White;
            }
            else
            {
                progressBar2.BackColor = Color.Lime;
            }

            if (profitDegree <= 0)
            {
                progressBar2.Value = 0;
                label4.Text = "100%";
                label7.Text = "0%";
            }
            else
            {
                float threat, profit, total;
                total = threatDegree + profitDegree;
                threat = threatDegree / total;
                profit = profitDegree / total;

                label4.Text = $"{Math.Round(threat * 100, 1)}%";
                label7.Text = $"{Math.Round(profit * 100, 1)}%";
                if ((int)(threat * 100) > 100)
                    progressBar2.Value = 100;
                else
                    progressBar2.Value = (int)(threat * 100);
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}
